export interface UserInfo {
  [key: string]: any;
  userId: string;
  tenantId: string;
  avatar: string;
  authority: string; // 角色
  userName: string;
  account: string;
}

interface UserState {
  userInfo: UserInfo | null;
  userDetail: Api.GetUserDetailRes | null;
}

export const useUserStore = defineStore("user", {
  state: (): UserState => {
    return {
      userInfo: null,
      userDetail: null,
    };
  },
  actions: {
    setUserInfo(userInfo: UserInfo | null) {
      this.userInfo = userInfo;
    },

    setUserDetail(info: Api.GetUserDetailRes | null) {
      this.userDetail = info;
    },
    clearUserInfo() {
      this.userInfo = null;
    },
  },
  getters: {},
  // persist: {
  // key: "test-key",
  // storage: sessionStorage,
  // pick: ["accessToken"],
  // beforeHydrate: (ctx) => {
  // console.log("----before restore: ", ctx.store, ctx);
  // },
  // afterHydrate: (ctx) => {
  //   console.log("after restore: ", ctx);
  // },
  // serializer: {
  //   serialize: () => {},
  //   deserialize: () => {},
  // },
  // },
});
